// src/lib/suspenseHelpers.ts
function createSuspendingResourceFromPromiseFactory(promiseFactory) {
  let status = "pending";
  let result;
  let error;
  let suspenderPromise;
  return {
    read() {
      if (!suspenderPromise) {
        suspenderPromise = promiseFactory().then(
          (resolvedValue) => {
            status = "success";
            result = resolvedValue;
          },
          (e) => {
            status = "error";
            error = e;
          }
        );
      }
      if (status === "pending") {
        throw suspenderPromise;
      } else if (status === "success") {
        return result;
      }
      throw error;
    }
  };
}
var moduleResourceByURL = /* @__PURE__ */ new Map();
function createPerModuleLoadResource(moduleURL) {
  let resource = moduleResourceByURL.get(moduleURL);
  if (resource) {
    return resource;
  }
  const moduleLoaderPromise = () => import(
    /* @vite-ignore */
    moduleURL
  );
  resource = createSuspendingResourceFromPromiseFactory(
    moduleLoaderPromise
  );
  moduleResourceByURL.set(moduleURL, resource);
  return resource;
}

export {
  createSuspendingResourceFromPromiseFactory,
  createPerModuleLoadResource
};
